#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 10005;

int n, m;
struct Cow {
  int mn, mx;
  bool operator<(const Cow& o) const { return mn < o.mn; }
} cows[N];
struct Stream {
  int val, cnt;
  bool operator<(const Stream& o) const { return val < o.val; }
} streams[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> cows[i].mn >> cows[i].mx;
  rep(i, 1, m) cin >> streams[i].val >> streams[i].cnt;
  sort(cows + 1, cows + n + 1);
  sort(streams + 1, streams + m + 1);
  priority_queue<int, vector<int>, greater<int>> pq;
  int ans = 0;
  int j = 1;
  rep(i, 1, m) {
    int val = streams[i].val, cnt = streams[i].cnt;
    while (j <= n && cows[j].mn <= val) pq.push(cows[j++].mx);
    while (pq.size() && pq.top() < val) pq.pop();
    while (pq.size() && cnt) pq.pop(), cnt--, ans++;
  }
  cout << ans;
  return 0;
}